package com.uphone.kingmall.activity.personal.set;

import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.china.zhuoyue.R;
import com.lzy.okgo.model.HttpParams;
import com.uphone.kingmall.base.BaseActivity;
import com.uphone.kingmall.utils.CommonUtil;
import com.uphone.kingmall.utils.MyUrl;
import com.uphone.kingmall.utils.SharedPreferencesHelper;
import com.uphone.kingmall.view.SubmitButton;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * <pre>
 *     author : 王雨
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2018/07/31
 *     desc   :会员名
 *     version: 1.0
 * </pre>
 */
public class MemberNameActivity extends BaseActivity {
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_str)
    EditText tvStr;
    @BindView(R.id.iv_clear)
    ImageView ivClear;
    @BindView(R.id.btn_save)
    SubmitButton btnSave;

    @Override
    public int getLayoutContentId() {
        return R.layout.kingmall_activity_member_name;
    }

    @Override
    public void initView() {
        setStatusBar();
        btnSave.setRelaViews(tvStr);
    }

    @Override
    public void initData() {
        if (!TextUtils.isEmpty(SharedPreferencesHelper.getUserName())) {
            tvStr.setText(SharedPreferencesHelper.getUserName() + "");
        }
    }


    @OnClick({R.id.iv_back, R.id.iv_clear, R.id.btn_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                onBackPressed();
                break;
            case R.id.iv_clear:
                tvStr.setText("");
                break;
            case R.id.btn_save:
                if (TextUtils.isEmpty(tvStr.getText().toString())) {
                    showShortToast("会员名不能为空");
                    return;
                }
                HttpParams params = new HttpParams();
                params.put("userName", tvStr.getText().toString().trim());
                CommonUtil.submitNetAndFinish(this, MyUrl.editUserName, params, "修改会员名成功！");
                break;
        }
    }
}
